//
//  WBTextAttachment.swift
//  SainMicroblog
//
//  Created by chenxinju on 16/5/16.
//  Copyright © 2016年 chenxinju-a2. All rights reserved.
//

import UIKit

class WBTextAttachment: NSTextAttachment {
    
    
    //拥有模型
    var emoticon : WBEmoticon?
    
    ///  抽取表情 NSAttributedString的代码
    ///
    ///  - parameter emoticon:   模型
    ///  - parameter fontHeight: 表情的高度
    ///
    ///  - returns: 
    class func getEmoiconAttributeString(emoticon: WBEmoticon,fontHeight:CGFloat) ->NSAttributedString{
      
        //1.创建一个添加实例的对象
        let attachemt = WBTextAttachment()
        
        attachemt.emoticon = emoticon
        
        //2.设置属性
        let imageName = "\(emoticon.package!)/\(emoticon.png!)"
        attachemt.image = UIImage(named: imageName)
        //设置图片的宽和高
        attachemt.bounds = CGRectMake(0,  -4, fontHeight, fontHeight)
        
        //2. 把附件设置给attrbutteString
        let attrbute = NSAttributedString(attachment: attachemt)
        
        return attrbute
    }

}
